{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "xgb_pred = pd.read_csv('../use_lda/pred.csv')\n",
    "gbc_pred = pd.read_csv('../1.各种模型比较/gbc_pred.csv')\n",
    "rfc_pred = pd.read_csv('../1.各种模型比较/rfc_pred.csv')\n",
    "lgb_pred = pd.read_csv('../1.各种模型比较/lgb_pred_en.csv')\n",
    "stack_pred_lg = pd.read_csv('./stack_pred1.csv')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 0.33 xgb_pred + 0.33 gbc_pred + 0.33 rfc_pred "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "ensemble_pred = xgb_pred[['id']]\n",
    "prob = xgb_pred['prob']\n",
    "\n",
    "prob += gbc_pred.prob\n",
    "prob += rfc_pred.prob\n",
    "ensemble_pred['prob'] = prob/3\n",
    "\n",
    "ensemble_pred.to_csv('./bagging_pred.csv',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 0.5 xgb_pred + 0.5 gbc_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "ensemble_pred = xgb_pred[['id']]\n",
    "prob = xgb_pred['prob']\n",
    "\n",
    "prob += gbc_pred.prob\n",
    "ensemble_pred['prob'] = prob/2\n",
    "ensemble_pred.to_csv('./bagging_pred1.csv',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 0.4 xgb_pred + 0.35 gbc_pred + 0.25 rfc_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "ensemble_pred = xgb_pred[['id']]\n",
    "prob = xgb_pred['prob']\n",
    "ensemble_pred['prob'] = 0.4*prob + 0.35*gbc_pred.prob + 0.25*rfc_pred.prob\n",
    "ensemble_pred.to_csv('./bagging_pred2.csv',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 0.2 xgb_pred + 0.35 gbc_pred + 0.45 rfc_pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "ensemble_pred = xgb_pred[['id']]\n",
    "prob = xgb_pred['prob']\n",
    "ensemble_pred['prob'] = 0.2*prob + 0.35*gbc_pred.prob + 0.45*rfc_pred.prob\n",
    "ensemble_pred.to_csv('./bagging_pred3.csv',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  xgb_pred + gbc_pred + rfc_pred + lgb_pred(democracy vate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "ensemble_pred = xgb_pred[['id']]\n",
    "prob = xgb_pred.prob+gbc_pred.prob+rfc_pred.prob+lgb_pred.prob\n",
    "ensemble_pred['prob'] = prob/4\n",
    "ensemble_pred.to_csv('./bagging_pred4.csv',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  xgb_pred + gbc_pred + rfc_pred + lgb_pred（weigthed vote）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "ensemble_pred = xgb_pred[['id']]\n",
    "prob = (3*xgb_pred.prob + 1*gbc_pred.prob + 1*rfc_pred.prob + 1*lgb_pred.prob)/6\n",
    "ensemble_pred['prob'] = prob\n",
    "ensemble_pred.to_csv('./bagging_pred5.csv',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  xgb_pred + gbc_pred + rfc_pred + lgb_pred + stack_pred_lg（weigthed vote）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "ensemble_pred = xgb_pred[['id']]\n",
    "prob = (3*xgb_pred.prob + 1*gbc_pred.prob + 1*rfc_pred.prob + 1*lgb_pred.prob + 1*stack_pred_lg.prob)/7\n",
    "ensemble_pred['prob'] = prob\n",
    "ensemble_pred.to_csv('./bagging_pred6.csv',index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 线上成绩：  \n",
    "使用GBC AUC:0.81958272831703   \n",
    "使用XGB AUC:0.82979480823375  \n",
    "使用RFC AUC:0.78512734928805  \n",
    "使用LGB_en AUC:0.8079"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### blending结果\n",
    "nodup + null + tag (fillna(-1)) AUC:0.82979480823375  \n",
    "(0.33 xgb_pred + 0.33 gbc_pred + 0.33 rfc_pred ）AUC:0.83126754015785  \n",
    "(0.33 xgb_pred + 0.33 gbc_pred1 + 0.33 rfc_pred ）AUC:0.83046460291442  \n",
    "(0.5 xgb_pred + 0.5 gbc_pred ) AUC:0.83105  \n",
    "(0.4 xgb_pred + 0.35 gbc_pred + 0.25 rfc_pred) AUC:0.8294481046602  \n",
    "(0.2 xgb_pred + 0.35 gbc_pred + 0.45 rfc_pred) AUC:0.82816585986015  \n",
    "（xgb_pred + gbc_pred + rfc_pred + lgb_pred）/4 AUC:0.83156  \n",
    "xgb_pred + gbc_pred + rfc_pred + lgb_pred（weigthed vote） AUC: 0.831751269737  \n",
    "xgb_pred + gbc_pred + rfc_pred + lgb_pred + stack_pred_lg（weigthed vote） AUC:0.8297  \n",
    "(3*xgb_pred.prob + 1*gbc_pred.prob + 1*rfc_pred.prob + 1*lgb_pred.prob + 1*use_maj_disc_scal_pred.prob) AUC:0.8313   \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
